/*
 * Copyright 2014 Lotres Technology, Co., Ltd. All rights reserved.
 */
package com.hoo.util;

import org.springframework.stereotype.Service;
import org.springside.modules.security.utils.Digests;
import org.springside.modules.utils.Encodes;
import com.hoo.service.account.AccountService;

/**
 * AuthUtils.java
 * 
 * @author ryenlea
 */
@Service
public class AuthUtils {
	
  public static String encryptPlainPassword(String plainPassword, byte[] salt) {
    byte[] hashedPassword =
        Digests.sha1(plainPassword.getBytes(), salt, AccountService.HASH_INTERATIONS);
    return Encodes.encodeHex(hashedPassword);
  }

  public static String[] generateSaltAndPassword(String plainPassword) {
    byte[] salt = Digests.generateSalt(AccountService.SALT_SIZE);
    String saltStr = Encodes.encodeHex(salt);
    String hashedPasswordStr = encryptPlainPassword(plainPassword, salt);
    return new String[] {saltStr, hashedPasswordStr};
  }
  
  
}
